<script>
import {calculateSeamRate} from "@/api/quality/seamRate";

export default {
  props: {
    userName: {
      type: String,
      default: ''
    },
    total: {
      type: Number,
      default: ''
    },
  },
  data() {
    return {
      seamRate: {
        totalLength: 0,
        defectLength: 0,
        passRate: 0
      },
      partClass:[
        { name: '一类', value: 'A', number:80 },
        { name: '二类', value: 'B', number:60 },
        { name: '三类', value: 'C', number:0 },
      ],
    }
  },
  async created() {
    await this.calculateSeamRate();
  },
  computed: {
    propName() {
      return this.userName;
    },
  },
  methods: {
    async calculateSeamRate() {
      try {
        const queryParams = { userName: this.propName };
        this.seamRate = await calculateSeamRate(queryParams);
      } catch (error) {
        console.error('Error fetching seam rate:', error);
      }
    },
  }
}
</script>

<template>
  <div class="page">
    <el-row type="flex" gutter="20">
      <el-col :span="12">
        <el-card shadow="hover" style="height:100%">
          <div slot="header">
            <span>零件许可</span>
          </div>
          <el-tag
            style="margin: 10px"
            v-if="total >= partItem.number"
            v-for="(partItem, index) in partClass"
            :key="index"
            effect="dark">{{ partItem.name }}零件</el-tag>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover" style="height:100%">
          <div slot="header">
            <span>近一年焊缝探伤合格率</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-statistic title="总长度(UT)">
                <template slot="formatter">
                  {{ seamRate.totalLength !== 0 ? parseFloat(seamRate.totalLength).toLocaleString() + 'mm' : '暂无数据' }}
                </template>
              </el-statistic>
            </el-col>
<!--            <el-col :span="8">-->
<!--              <el-statistic title="不合格长度">-->
<!--                <template slot="formatter">-->
<!--                  {{ seamRate.defectLength !== 0 ? parseFloat(seamRate.defectLength).toLocaleString() + 'mm' : '暂无数据' }}-->
<!--                </template>-->
<!--              </el-statistic>-->
<!--            </el-col>-->
            <el-col :span="12">
              <el-statistic title="合格率">
                <template slot="prefix">
                  <i class="el-icon-s-flag" style="color: blue"></i>
                </template>
                <template slot="formatter">
                  {{ seamRate.passRate !== 0 ? seamRate.passRate + '%' : '暂无数据' }}
                </template>
              </el-statistic>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <div style="clear:both"></div>
    </el-row>
  </div>
</template>

<style scoped lang="scss">
/* 在这里可以添加样式 */
.page {
  padding: 24px;
}
</style>
